
<!DOCTYPE HTML>
<html lang="" >
    <head>
        <meta charset="UTF-8">
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <title>Monitor · GitBook</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="description" content="">
        <meta name="generator" content="GitBook 3.2.3">
        
        
        
    
    <link rel="stylesheet" href="../gitbook/style.css">

    
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-highlight/website.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-search/search.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-fontsettings/website.css">
                
            
        

    

    
        
    
        
    
        
    
        
    
        
    
        
    

        
    
    
    <meta name="HandheldFriendly" content="true"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../gitbook/images/apple-touch-icon-precomposed-152.png">
    <link rel="shortcut icon" href="../gitbook/images/favicon.ico" type="image/x-icon">

    
    <link rel="next" href="performance.html" />
    
    
    <link rel="prev" href="modal.html" />
    

    </head>
    <body>
        
<div class="book">
    <div class="book-summary">
        
            
<div id="book-search-input" role="search">
    <input type="text" placeholder="Type to search" />
</div>

            
                <nav role="navigation">
                


<ul class="summary">
    
    

    

    
        
        
    
        <li class="chapter " data-level="1.1" data-path="../">
            
                <a href="../">
            
                    
                    Introduction
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2" data-path="./">
            
                <a href="./">
            
                    
                    前端进阶
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3" data-path="Grid System.html">
            
                <a href="Grid System.html">
            
                    
                    Grid System
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4" data-path="Handwritten signature.html">
            
                <a href="Handwritten signature.html">
            
                    
                    Handwritten Signature
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5" data-path="Mobile Soft Keyboard.html">
            
                <a href="Mobile Soft Keyboard.html">
            
                    
                    Mobile Soft Keyboard
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6" data-path="authentication.html">
            
                <a href="authentication.html">
            
                    
                    Authentication
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7" >
            
                <span>
            
                    
                    Code
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.7.1" >
            
                <span>
            
                    
                    Four Operations
            
                </span>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.8" data-path="control loading.html">
            
                <a href="control loading.html">
            
                    
                    Control Loading
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9" data-path="downfile.html">
            
                <a href="downfile.html">
            
                    
                    Downfile
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.10" data-path="dynamic-routing.html">
            
                <a href="dynamic-routing.html">
            
                    
                    Dynamic Routing
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11" data-path="ecs.html">
            
                <a href="ecs.html">
            
                    
                    Ecs
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.12" data-path="engineering.html">
            
                <a href="engineering.html">
            
                    
                    Engineering
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.13" data-path="eslint-vscode-format.html">
            
                <a href="eslint-vscode-format.html">
            
                    
                    Eslint Vscode Format
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.14" data-path="eventloop.html">
            
                <a href="eventloop.html">
            
                    
                    Eventloop
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.15" data-path="four-operations-1.html">
            
                <a href="four-operations-1.html">
            
                    
                    Four Operations 1
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.16" data-path="four-operations-2.html">
            
                <a href="four-operations-2.html">
            
                    
                    Four Operations 2
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.17" data-path="four-operations-3.html">
            
                <a href="four-operations-3.html">
            
                    
                    Four Operations 3
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.18" data-path="four-operations-4.html">
            
                <a href="four-operations-4.html">
            
                    
                    Four Operations 4
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.19" data-path="front end summary.html">
            
                <a href="front end summary.html">
            
                    
                    Front End Summary
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.20" data-path="git commit style.html">
            
                <a href="git commit style.html">
            
                    
                    Git Commit Style
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.21" data-path="git-commands.html">
            
                <a href="git-commands.html">
            
                    
                    Git Commands
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.22" data-path="high-quality-code.html">
            
                <a href="high-quality-code.html">
            
                    
                    High Quality Code
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.23" data-path="history.html">
            
                <a href="history.html">
            
                    
                    History
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.24" data-path="html-tag.html">
            
                <a href="html-tag.html">
            
                    
                    Html Tag
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.25" data-path="http-https-http2.html">
            
                <a href="http-https-http2.html">
            
                    
                    Http Https Http2
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.26" data-path="ignore log.html">
            
                <a href="ignore log.html">
            
                    
                    Ignore Log
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.27" >
            
                <span>
            
                    
                    Imgs
            
                </span>
            

            
        </li>
    
        <li class="chapter " data-level="1.28" data-path="javascript-optimization.html">
            
                <a href="javascript-optimization.html">
            
                    
                    Javascript Optimization
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.29" data-path="local application.html">
            
                <a href="local application.html">
            
                    
                    Local Application
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.30" data-path="locality.html">
            
                <a href="locality.html">
            
                    
                    Locality
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.31" data-path="loop-unrolling.html">
            
                <a href="loop-unrolling.html">
            
                    
                    Loop Unrolling
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.32" data-path="mobile recommendation.html">
            
                <a href="mobile recommendation.html">
            
                    
                    Mobile Recommendation
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.33" data-path="modal.html">
            
                <a href="modal.html">
            
                    
                    Modal
            
                </a>
            

            
        </li>
    
        <li class="chapter active" data-level="1.34" data-path="monitor.html">
            
                <a href="monitor.html">
            
                    
                    Monitor
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.35" data-path="performance.html">
            
                <a href="performance.html">
            
                    
                    Performance
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.36" data-path="print-talbe.html">
            
                <a href="print-talbe.html">
            
                    
                    Print Talbe
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.37" data-path="promise.html">
            
                <a href="promise.html">
            
                    
                    Promise
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.38" data-path="teaching.html">
            
                <a href="teaching.html">
            
                    
                    Teaching
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.39" data-path="vue refresh.html">
            
                <a href="vue refresh.html">
            
                    
                    Vue Refresh
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.40" data-path="vue-page-not-refresh.html">
            
                <a href="vue-page-not-refresh.html">
            
                    
                    Vue Page Not Refresh
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.41" data-path="why-learn-theory.html">
            
                <a href="why-learn-theory.html">
            
                    
                    Why Learn Theory
            
                </a>
            

            
        </li>
    

    

    <li class="divider"></li>

    <li>
        <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
            Published with GitBook
        </a>
    </li>
</ul>


                </nav>
            
        
    </div>

    <div class="book-body">
        
            <div class="body-inner">
                
                    

<div class="book-header" role="navigation">
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href=".." >Monitor</a>
    </h1>
</div>




                    <div class="page-wrapper" tabindex="-1" role="main">
                        <div class="page-inner">
                            
<div id="book-search-results">
    <div class="search-noresults">
    
                                <section class="normal markdown-section">
                                
                                <h1 id="&#x524D;&#x7AEF;&#x6027;&#x80FD;&#x548C;&#x9519;&#x8BEF;&#x76D1;&#x63A7;">&#x524D;&#x7AEF;&#x6027;&#x80FD;&#x548C;&#x9519;&#x8BEF;&#x76D1;&#x63A7;</h1>
<h2 id="&#x524D;&#x8A00;">&#x524D;&#x8A00;</h2>
<p>&#x8FD9;&#x51E0;&#x5929;&#x5FC3;&#x8840;&#x6765;&#x6F6E;&#xFF0C;&#x60F3;&#x4E86;&#x89E3;&#x4E00;&#x4E0B;&#x524D;&#x7AEF;&#x76D1;&#x63A7;&#x7684;&#x76F8;&#x5173;&#x77E5;&#x8BC6;&#xFF0C;&#x53EF;&#x662F;&#x5728;&#x67E5;&#x770B;&#x4E86;&#x5F88;&#x591A;&#x8D44;&#x6599;&#x4E4B;&#x540E;&#xFF0C;&#x53D1;&#x73B0;&#x6CA1;&#x6709;&#x8BE6;&#x7EC6;&#x4ECB;&#x7ECD;&#x524D;&#x7AEF;&#x76D1;&#x63A7;&#x7684;&#x76F8;&#x5173;&#x6587;&#x7AE0;&#xFF0C;&#x90FD;&#x662F;&#x8BB2;&#x4E2A;&#x5927;&#x6982;&#xFF0C;&#x53CD;&#x5012;&#x662F;&#x73B0;&#x6210;&#x7684;&#x524D;&#x7AEF;&#x76D1;&#x63A7;&#x5DE5;&#x5177;&#x6709;&#x4E0D;&#x5C11;&#x3002;</p>
<p>&#x4E3A;&#x4E86;&#x6DF1;&#x5165;&#x5B66;&#x4E60;&#x524D;&#x7AEF;&#x76D1;&#x63A7;&#x7684;&#x76F8;&#x5173;&#x6280;&#x672F;&#x539F;&#x7406;&#xFF0C;&#x8FD9;&#x51E0;&#x5929;&#x90FD;&#x5728;&#x67E5;&#x9605;&#x76F8;&#x5173;&#x7684;&#x8D44;&#x6599;&#x3002;&#x73B0;&#x5728;&#x6253;&#x7B97;&#x5199;&#x4E00;&#x7BC7;&#x6587;&#x7AE0;&#x8BE6;&#x7EC6;&#x4ECB;&#x7ECD;&#x4E00;&#x4E0B;&#x524D;&#x7AEF;&#x76D1;&#x63A7;&#xFF0C;&#x5BF9;&#x8FD9;&#x51E0;&#x5929;&#x7684;&#x7814;&#x7A76;&#x505A;&#x4E00;&#x4E2A;&#x603B;&#x7ED3;&#xFF08;&#x4E8E;&#x662F;&#x5C31;&#x6709;&#x4E86;&#x672C;&#x6587;&#xFF09;&#x3002;</p>
<pre><code class="lang-js"><span class="hljs-comment">// &#x524D;&#x7AEF;&#x76D1;&#x63A7;&#x6D41;&#x7A0B;</span>
&#x6570;&#x636E;&#x91C7;&#x96C6; --&gt; &#x6570;&#x636E;&#x4E0A;&#x62A5; --&gt; &#x670D;&#x52A1;&#x7AEF;&#x5904;&#x7406; --&gt; &#x6570;&#x636E;&#x5E93;&#x5B58;&#x50A8; --&gt; &#x6570;&#x636E;&#x76D1;&#x63A7;&#x53EF;&#x89C6;&#x5316;&#x5E73;&#x53F0;
</code></pre>
<p>&#x4E0D;&#x8FC7;&#xFF0C;&#x672C;&#x6587;&#x53EA;&#x8BB2;&#x76D1;&#x63A7;&#x4E2D;&#x7684;&#x6570;&#x636E;&#x91C7;&#x96C6;&#x548C;&#x6570;&#x636E;&#x4E0A;&#x62A5;&#x4E24;&#x4E2A;&#x6B65;&#x9AA4;&#xFF0C;&#x540E;&#x7EED;&#x6D41;&#x7A0B;&#x9700;&#x8BFB;&#x8005;&#x81EA;&#x884C;&#x7814;&#x7A76;&#x63A2;&#x7D22;&#xFF08;&#x8FD9;&#x4E5F;&#x662F;&#x4E00;&#x79CD;&#x4E50;&#x8DA3;&#xFF09;&#x3002;</p>
<h2 id="&#x6570;&#x636E;&#x91C7;&#x96C6;">&#x6570;&#x636E;&#x91C7;&#x96C6;</h2>
<h3 id="&#x6027;&#x80FD;&#x6570;&#x636E;&#x91C7;&#x96C6;">&#x6027;&#x80FD;&#x6570;&#x636E;&#x91C7;&#x96C6;</h3>
<p>&#x5148;&#x6765;&#x4E86;&#x89E3;&#x4E00;&#x4E0B; Web API <a href="https://developer.mozilla.org/zh-CN/docs/Web/API/Performance" target="_blank">window.performance</a> &#x3002;</p>
<blockquote>
<p>Performance &#x63A5;&#x53E3;&#x53EF;&#x4EE5;&#x83B7;&#x53D6;&#x5230;&#x5F53;&#x524D;&#x9875;&#x9762;&#x4E2D;&#x4E0E;&#x6027;&#x80FD;&#x76F8;&#x5173;&#x7684;&#x4FE1;&#x606F;&#xFF0C;&#x5B83;&#x662F; High Resolution Time API &#x7684;&#x4E00;&#x90E8;&#x5206;&#xFF0C;&#x540C;&#x65F6;&#x4E5F;&#x878D;&#x5408;&#x4E86; Performance Timeline API&#x3001;Navigation Timing API&#x3001; User Timing API &#x548C; Resource Timing API&#x3002;</p>
</blockquote>
<p>&#x8FD9;&#x4E2A; API &#x7684;&#x5C5E;&#x6027; <code>timing</code>&#xFF0C;&#x5305;&#x542B;&#x4E86;&#x9875;&#x9762;&#x52A0;&#x8F7D;&#x5404;&#x4E2A;&#x9636;&#x6BB5;&#x7684;&#x8D77;&#x59CB;&#x53CA;&#x7ED3;&#x675F;&#x65F6;&#x95F4;&#x3002;</p>
<p><img src="https://github.com/woai3c/Front-end-articles/blob/master/imgs/monitor1.png" alt="&#x5728;&#x8FD9;&#x91CC;&#x63D2;&#x5165;&#x56FE;&#x7247;&#x63CF;&#x8FF0;"></p>
<p><img src="https://github.com/woai3c/Front-end-articles/blob/master/imgs/monitor2.jpg" alt="&#x5728;&#x8FD9;&#x91CC;&#x63D2;&#x5165;&#x56FE;&#x7247;&#x63CF;&#x8FF0;"></p>
<p>&#x4E3A;&#x4E86;&#x65B9;&#x4FBF;&#x5927;&#x5BB6;&#x7406;&#x89E3; <code>timing</code> &#x5404;&#x4E2A;&#x5C5E;&#x6027;&#x7684;&#x610F;&#x4E49;&#xFF0C;&#x6211;&#x5728;&#x77E5;&#x4E4E;&#x627E;&#x5230;&#x4E00;&#x4F4D;&#x7F51;&#x53CB;&#x5BF9;&#x4E8E; <code>timing</code> &#x5199;&#x7684;&#x7B80;&#x4ECB;&#xFF0C;&#x5728;&#x6B64;&#x8F6C;&#x8F7D;&#x4E00;&#x4E0B;&#x3002;</p>
<pre><code class="lang-js">timing: {
        <span class="hljs-comment">// &#x540C;&#x4E00;&#x4E2A;&#x6D4F;&#x89C8;&#x5668;&#x4E0A;&#x4E00;&#x4E2A;&#x9875;&#x9762;&#x5378;&#x8F7D;(unload)&#x7ED3;&#x675F;&#x65F6;&#x7684;&#x65F6;&#x95F4;&#x6233;&#x3002;&#x5982;&#x679C;&#x6CA1;&#x6709;&#x4E0A;&#x4E00;&#x4E2A;&#x9875;&#x9762;&#xFF0C;&#x8FD9;&#x4E2A;&#x503C;&#x4F1A;&#x548C;fetchStart&#x76F8;&#x540C;&#x3002;</span>
    navigationStart: <span class="hljs-number">1543806782096</span>,

    <span class="hljs-comment">// &#x4E0A;&#x4E00;&#x4E2A;&#x9875;&#x9762;unload&#x4E8B;&#x4EF6;&#x629B;&#x51FA;&#x65F6;&#x7684;&#x65F6;&#x95F4;&#x6233;&#x3002;&#x5982;&#x679C;&#x6CA1;&#x6709;&#x4E0A;&#x4E00;&#x4E2A;&#x9875;&#x9762;&#xFF0C;&#x8FD9;&#x4E2A;&#x503C;&#x4F1A;&#x8FD4;&#x56DE;0&#x3002;</span>
    unloadEventStart: <span class="hljs-number">1543806782523</span>,

    <span class="hljs-comment">// &#x548C; unloadEventStart &#x76F8;&#x5BF9;&#x5E94;&#xFF0C;unload&#x4E8B;&#x4EF6;&#x5904;&#x7406;&#x5B8C;&#x6210;&#x65F6;&#x7684;&#x65F6;&#x95F4;&#x6233;&#x3002;&#x5982;&#x679C;&#x6CA1;&#x6709;&#x4E0A;&#x4E00;&#x4E2A;&#x9875;&#x9762;,&#x8FD9;&#x4E2A;&#x503C;&#x4F1A;&#x8FD4;&#x56DE;0&#x3002;</span>
    unloadEventEnd: <span class="hljs-number">1543806782523</span>,

    <span class="hljs-comment">// &#x7B2C;&#x4E00;&#x4E2A;HTTP&#x91CD;&#x5B9A;&#x5411;&#x5F00;&#x59CB;&#x65F6;&#x7684;&#x65F6;&#x95F4;&#x6233;&#x3002;&#x5982;&#x679C;&#x6CA1;&#x6709;&#x91CD;&#x5B9A;&#x5411;&#xFF0C;&#x6216;&#x8005;&#x91CD;&#x5B9A;&#x5411;&#x4E2D;&#x7684;&#x4E00;&#x4E2A;&#x4E0D;&#x540C;&#x6E90;&#xFF0C;&#x8FD9;&#x4E2A;&#x503C;&#x4F1A;&#x8FD4;&#x56DE;0&#x3002;</span>
    redirectStart: <span class="hljs-number">0</span>,

    <span class="hljs-comment">// &#x6700;&#x540E;&#x4E00;&#x4E2A;HTTP&#x91CD;&#x5B9A;&#x5411;&#x5B8C;&#x6210;&#x65F6;&#xFF08;&#x4E5F;&#x5C31;&#x662F;&#x8BF4;&#x662F;HTTP&#x54CD;&#x5E94;&#x7684;&#x6700;&#x540E;&#x4E00;&#x4E2A;&#x6BD4;&#x7279;&#x76F4;&#x63A5;&#x88AB;&#x6536;&#x5230;&#x7684;&#x65F6;&#x95F4;&#xFF09;&#x7684;&#x65F6;&#x95F4;&#x6233;&#x3002;</span>
    <span class="hljs-comment">// &#x5982;&#x679C;&#x6CA1;&#x6709;&#x91CD;&#x5B9A;&#x5411;&#xFF0C;&#x6216;&#x8005;&#x91CD;&#x5B9A;&#x5411;&#x4E2D;&#x7684;&#x4E00;&#x4E2A;&#x4E0D;&#x540C;&#x6E90;&#xFF0C;&#x8FD9;&#x4E2A;&#x503C;&#x4F1A;&#x8FD4;&#x56DE;0. </span>
    redirectEnd: <span class="hljs-number">0</span>,

    <span class="hljs-comment">// &#x6D4F;&#x89C8;&#x5668;&#x51C6;&#x5907;&#x597D;&#x4F7F;&#x7528;HTTP&#x8BF7;&#x6C42;&#x6765;&#x83B7;&#x53D6;(fetch)&#x6587;&#x6863;&#x7684;&#x65F6;&#x95F4;&#x6233;&#x3002;&#x8FD9;&#x4E2A;&#x65F6;&#x95F4;&#x70B9;&#x4F1A;&#x5728;&#x68C0;&#x67E5;&#x4EFB;&#x4F55;&#x5E94;&#x7528;&#x7F13;&#x5B58;&#x4E4B;&#x524D;&#x3002;</span>
    fetchStart: <span class="hljs-number">1543806782096</span>,

    <span class="hljs-comment">// DNS &#x57DF;&#x540D;&#x67E5;&#x8BE2;&#x5F00;&#x59CB;&#x7684;UNIX&#x65F6;&#x95F4;&#x6233;&#x3002;</span>
        <span class="hljs-comment">//&#x5982;&#x679C;&#x4F7F;&#x7528;&#x4E86;&#x6301;&#x7EED;&#x8FDE;&#x63A5;(persistent connection)&#xFF0C;&#x6216;&#x8005;&#x8FD9;&#x4E2A;&#x4FE1;&#x606F;&#x5B58;&#x50A8;&#x5230;&#x4E86;&#x7F13;&#x5B58;&#x6216;&#x8005;&#x672C;&#x5730;&#x8D44;&#x6E90;&#x4E0A;&#xFF0C;&#x8FD9;&#x4E2A;&#x503C;&#x5C06;&#x548C;fetchStart&#x4E00;&#x81F4;&#x3002;</span>
    domainLookupStart: <span class="hljs-number">1543806782096</span>,

    <span class="hljs-comment">// DNS &#x57DF;&#x540D;&#x67E5;&#x8BE2;&#x5B8C;&#x6210;&#x7684;&#x65F6;&#x95F4;.</span>
    <span class="hljs-comment">//&#x5982;&#x679C;&#x4F7F;&#x7528;&#x4E86;&#x672C;&#x5730;&#x7F13;&#x5B58;&#xFF08;&#x5373;&#x65E0; DNS &#x67E5;&#x8BE2;&#xFF09;&#x6216;&#x6301;&#x4E45;&#x8FDE;&#x63A5;&#xFF0C;&#x5219;&#x4E0E; fetchStart &#x503C;&#x76F8;&#x7B49;</span>
    domainLookupEnd: <span class="hljs-number">1543806782096</span>,

    <span class="hljs-comment">// HTTP&#xFF08;TCP&#xFF09; &#x57DF;&#x540D;&#x67E5;&#x8BE2;&#x7ED3;&#x675F;&#x7684;&#x65F6;&#x95F4;&#x6233;&#x3002;</span>
        <span class="hljs-comment">//&#x5982;&#x679C;&#x4F7F;&#x7528;&#x4E86;&#x6301;&#x7EED;&#x8FDE;&#x63A5;(persistent connection)&#xFF0C;&#x6216;&#x8005;&#x8FD9;&#x4E2A;&#x4FE1;&#x606F;&#x5B58;&#x50A8;&#x5230;&#x4E86;&#x7F13;&#x5B58;&#x6216;&#x8005;&#x672C;&#x5730;&#x8D44;&#x6E90;&#x4E0A;&#xFF0C;&#x8FD9;&#x4E2A;&#x503C;&#x5C06;&#x548C; fetchStart&#x4E00;&#x81F4;&#x3002;</span>
    connectStart: <span class="hljs-number">1543806782099</span>,

    <span class="hljs-comment">// HTTP&#xFF08;TCP&#xFF09; &#x8FD4;&#x56DE;&#x6D4F;&#x89C8;&#x5668;&#x4E0E;&#x670D;&#x52A1;&#x5668;&#x4E4B;&#x95F4;&#x7684;&#x8FDE;&#x63A5;&#x5EFA;&#x7ACB;&#x65F6;&#x7684;&#x65F6;&#x95F4;&#x6233;&#x3002;</span>
        <span class="hljs-comment">// &#x5982;&#x679C;&#x5EFA;&#x7ACB;&#x7684;&#x662F;&#x6301;&#x4E45;&#x8FDE;&#x63A5;&#xFF0C;&#x5219;&#x8FD4;&#x56DE;&#x503C;&#x7B49;&#x540C;&#x4E8E;fetchStart&#x5C5E;&#x6027;&#x7684;&#x503C;&#x3002;&#x8FDE;&#x63A5;&#x5EFA;&#x7ACB;&#x6307;&#x7684;&#x662F;&#x6240;&#x6709;&#x63E1;&#x624B;&#x548C;&#x8BA4;&#x8BC1;&#x8FC7;&#x7A0B;&#x5168;&#x90E8;&#x7ED3;&#x675F;&#x3002;</span>
    connectEnd: <span class="hljs-number">1543806782227</span>,

    <span class="hljs-comment">// HTTPS &#x8FD4;&#x56DE;&#x6D4F;&#x89C8;&#x5668;&#x4E0E;&#x670D;&#x52A1;&#x5668;&#x5F00;&#x59CB;&#x5B89;&#x5168;&#x94FE;&#x63A5;&#x7684;&#x63E1;&#x624B;&#x65F6;&#x7684;&#x65F6;&#x95F4;&#x6233;&#x3002;&#x5982;&#x679C;&#x5F53;&#x524D;&#x7F51;&#x9875;&#x4E0D;&#x8981;&#x6C42;&#x5B89;&#x5168;&#x8FDE;&#x63A5;&#xFF0C;&#x5219;&#x8FD4;&#x56DE;0&#x3002;</span>
    secureConnectionStart: <span class="hljs-number">1543806782162</span>,

    <span class="hljs-comment">// &#x8FD4;&#x56DE;&#x6D4F;&#x89C8;&#x5668;&#x5411;&#x670D;&#x52A1;&#x5668;&#x53D1;&#x51FA;HTTP&#x8BF7;&#x6C42;&#x65F6;&#xFF08;&#x6216;&#x5F00;&#x59CB;&#x8BFB;&#x53D6;&#x672C;&#x5730;&#x7F13;&#x5B58;&#x65F6;&#xFF09;&#x7684;&#x65F6;&#x95F4;&#x6233;&#x3002;</span>
    requestStart: <span class="hljs-number">1543806782241</span>,

    <span class="hljs-comment">// &#x8FD4;&#x56DE;&#x6D4F;&#x89C8;&#x5668;&#x4ECE;&#x670D;&#x52A1;&#x5668;&#x6536;&#x5230;&#xFF08;&#x6216;&#x4ECE;&#x672C;&#x5730;&#x7F13;&#x5B58;&#x8BFB;&#x53D6;&#xFF09;&#x7B2C;&#x4E00;&#x4E2A;&#x5B57;&#x8282;&#x65F6;&#x7684;&#x65F6;&#x95F4;&#x6233;&#x3002;</span>
        <span class="hljs-comment">//&#x5982;&#x679C;&#x4F20;&#x8F93;&#x5C42;&#x5728;&#x5F00;&#x59CB;&#x8BF7;&#x6C42;&#x4E4B;&#x540E;&#x5931;&#x8D25;&#x5E76;&#x4E14;&#x8FDE;&#x63A5;&#x88AB;&#x91CD;&#x5F00;&#xFF0C;&#x8BE5;&#x5C5E;&#x6027;&#x5C06;&#x4F1A;&#x88AB;&#x6570;&#x5236;&#x6210;&#x65B0;&#x7684;&#x8BF7;&#x6C42;&#x7684;&#x76F8;&#x5BF9;&#x5E94;&#x7684;&#x53D1;&#x8D77;&#x65F6;&#x95F4;&#x3002;</span>
    responseStart: <span class="hljs-number">1543806782516</span>,

    <span class="hljs-comment">// &#x8FD4;&#x56DE;&#x6D4F;&#x89C8;&#x5668;&#x4ECE;&#x670D;&#x52A1;&#x5668;&#x6536;&#x5230;&#xFF08;&#x6216;&#x4ECE;&#x672C;&#x5730;&#x7F13;&#x5B58;&#x8BFB;&#x53D6;&#xFF0C;&#x6216;&#x4ECE;&#x672C;&#x5730;&#x8D44;&#x6E90;&#x8BFB;&#x53D6;&#xFF09;&#x6700;&#x540E;&#x4E00;&#x4E2A;&#x5B57;&#x8282;&#x65F6;</span>
        <span class="hljs-comment">//&#xFF08;&#x5982;&#x679C;&#x5728;&#x6B64;&#x4E4B;&#x524D;HTTP&#x8FDE;&#x63A5;&#x5DF2;&#x7ECF;&#x5173;&#x95ED;&#xFF0C;&#x5219;&#x8FD4;&#x56DE;&#x5173;&#x95ED;&#x65F6;&#xFF09;&#x7684;&#x65F6;&#x95F4;&#x6233;&#x3002;</span>
    responseEnd: <span class="hljs-number">1543806782537</span>,

    <span class="hljs-comment">// &#x5F53;&#x524D;&#x7F51;&#x9875;DOM&#x7ED3;&#x6784;&#x5F00;&#x59CB;&#x89E3;&#x6790;&#x65F6;&#xFF08;&#x5373;Document.readyState&#x5C5E;&#x6027;&#x53D8;&#x4E3A;&#x201C;loading&#x201D;&#x3001;&#x76F8;&#x5E94;&#x7684; readystatechange&#x4E8B;&#x4EF6;&#x89E6;&#x53D1;&#x65F6;&#xFF09;&#x7684;&#x65F6;&#x95F4;&#x6233;&#x3002;</span>
    domLoading: <span class="hljs-number">1543806782573</span>,

    <span class="hljs-comment">// &#x5F53;&#x524D;&#x7F51;&#x9875;DOM&#x7ED3;&#x6784;&#x7ED3;&#x675F;&#x89E3;&#x6790;&#x3001;&#x5F00;&#x59CB;&#x52A0;&#x8F7D;&#x5185;&#x5D4C;&#x8D44;&#x6E90;&#x65F6;&#xFF08;&#x5373;Document.readyState&#x5C5E;&#x6027;&#x53D8;&#x4E3A;&#x201C;interactive&#x201D;&#x3001;&#x76F8;&#x5E94;&#x7684;readystatechange&#x4E8B;&#x4EF6;&#x89E6;&#x53D1;&#x65F6;&#xFF09;&#x7684;&#x65F6;&#x95F4;&#x6233;&#x3002;</span>
    domInteractive: <span class="hljs-number">1543806783203</span>,

    <span class="hljs-comment">// &#x5F53;&#x89E3;&#x6790;&#x5668;&#x53D1;&#x9001;DOMContentLoaded &#x4E8B;&#x4EF6;&#xFF0C;&#x5373;&#x6240;&#x6709;&#x9700;&#x8981;&#x88AB;&#x6267;&#x884C;&#x7684;&#x811A;&#x672C;&#x5DF2;&#x7ECF;&#x88AB;&#x89E3;&#x6790;&#x65F6;&#x7684;&#x65F6;&#x95F4;&#x6233;&#x3002;</span>
    domContentLoadedEventStart: <span class="hljs-number">1543806783203</span>,

    <span class="hljs-comment">// &#x5F53;&#x6240;&#x6709;&#x9700;&#x8981;&#x7ACB;&#x5373;&#x6267;&#x884C;&#x7684;&#x811A;&#x672C;&#x5DF2;&#x7ECF;&#x88AB;&#x6267;&#x884C;&#xFF08;&#x4E0D;&#x8BBA;&#x6267;&#x884C;&#x987A;&#x5E8F;&#xFF09;&#x65F6;&#x7684;&#x65F6;&#x95F4;&#x6233;&#x3002;</span>
    domContentLoadedEventEnd: <span class="hljs-number">1543806783216</span>,

    <span class="hljs-comment">// &#x5F53;&#x524D;&#x6587;&#x6863;&#x89E3;&#x6790;&#x5B8C;&#x6210;&#xFF0C;&#x5373;Document.readyState &#x53D8;&#x4E3A; &apos;complete&apos;&#x4E14;&#x76F8;&#x5BF9;&#x5E94;&#x7684;readystatechange &#x88AB;&#x89E6;&#x53D1;&#x65F6;&#x7684;&#x65F6;&#x95F4;&#x6233;</span>
    domComplete: <span class="hljs-number">1543806783796</span>,

    <span class="hljs-comment">// load&#x4E8B;&#x4EF6;&#x88AB;&#x53D1;&#x9001;&#x65F6;&#x7684;&#x65F6;&#x95F4;&#x6233;&#x3002;&#x5982;&#x679C;&#x8FD9;&#x4E2A;&#x4E8B;&#x4EF6;&#x8FD8;&#x672A;&#x88AB;&#x53D1;&#x9001;&#xFF0C;&#x5B83;&#x7684;&#x503C;&#x5C06;&#x4F1A;&#x662F;0&#x3002;</span>
    loadEventStart: <span class="hljs-number">1543806783796</span>,

    <span class="hljs-comment">// &#x5F53;load&#x4E8B;&#x4EF6;&#x7ED3;&#x675F;&#xFF0C;&#x5373;&#x52A0;&#x8F7D;&#x4E8B;&#x4EF6;&#x5B8C;&#x6210;&#x65F6;&#x7684;&#x65F6;&#x95F4;&#x6233;&#x3002;&#x5982;&#x679C;&#x8FD9;&#x4E2A;&#x4E8B;&#x4EF6;&#x8FD8;&#x672A;&#x88AB;&#x53D1;&#x9001;&#xFF0C;&#x6216;&#x8005;&#x5C1A;&#x672A;&#x5B8C;&#x6210;&#xFF0C;&#x5B83;&#x7684;&#x503C;&#x5C06;&#x4F1A;&#x662F;0.</span>
    loadEventEnd: <span class="hljs-number">1543806783802</span>
}
</code></pre>
<p>&#x901A;&#x8FC7;&#x4EE5;&#x4E0A;&#x6570;&#x636E;&#xFF0C;&#x6211;&#x4EEC;&#x53EF;&#x4EE5;&#x5F97;&#x5230;&#x51E0;&#x4E2A;&#x6709;&#x7528;&#x7684;&#x65F6;&#x95F4;</p>
<pre><code class="lang-js"><span class="hljs-comment">// &#x91CD;&#x5B9A;&#x5411;&#x8017;&#x65F6;</span>
redirect: timing.redirectEnd - timing.redirectStart,
<span class="hljs-comment">// DOM &#x6E32;&#x67D3;&#x8017;&#x65F6;</span>
dom: timing.domComplete - timing.domLoading,
<span class="hljs-comment">// &#x9875;&#x9762;&#x52A0;&#x8F7D;&#x8017;&#x65F6;</span>
load: timing.loadEventEnd - timing.navigationStart,
<span class="hljs-comment">// &#x9875;&#x9762;&#x5378;&#x8F7D;&#x8017;&#x65F6;</span>
unload: timing.unloadEventEnd - timing.unloadEventStart,
<span class="hljs-comment">// &#x8BF7;&#x6C42;&#x8017;&#x65F6;</span>
request: timing.responseEnd - timing.requestStart,
<span class="hljs-comment">// &#x83B7;&#x53D6;&#x6027;&#x80FD;&#x4FE1;&#x606F;&#x65F6;&#x5F53;&#x524D;&#x65F6;&#x95F4;</span>
time: <span class="hljs-keyword">new</span> <span class="hljs-built_in">Date</span>().getTime(),
</code></pre>
<p>&#x8FD8;&#x6709;&#x4E00;&#x4E2A;&#x6BD4;&#x8F83;&#x91CD;&#x8981;&#x7684;&#x65F6;&#x95F4;&#x5C31;&#x662F;<strong>&#x767D;&#x5C4F;&#x65F6;&#x95F4;</strong>&#xFF0C;&#x5B83;&#x6307;&#x4ECE;&#x8F93;&#x5165;&#x7F51;&#x5740;&#xFF0C;&#x5230;&#x9875;&#x9762;&#x5F00;&#x59CB;&#x663E;&#x793A;&#x5185;&#x5BB9;&#x7684;&#x65F6;&#x95F4;&#x3002;</p>
<p>&#x5C06;&#x4EE5;&#x4E0B;&#x811A;&#x672C;&#x653E;&#x5728; <code>&lt;/head&gt;</code> &#x524D;&#x9762;&#x5C31;&#x80FD;&#x83B7;&#x53D6;&#x767D;&#x5C4F;&#x65F6;&#x95F4;&#x3002;</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">script</span>&gt;</span><span class="javascript">
    whiteScreen = <span class="hljs-keyword">new</span> <span class="hljs-built_in">Date</span>() - performance.timing.navigationStart
</span><span class="hljs-tag">&lt;/<span class="hljs-name">script</span>&gt;</span>
</code></pre>
<p>&#x901A;&#x8FC7;&#x8FD9;&#x51E0;&#x4E2A;&#x65F6;&#x95F4;&#xFF0C;&#x5C31;&#x53EF;&#x4EE5;&#x5F97;&#x77E5;&#x9875;&#x9762;&#x9996;&#x5C4F;&#x52A0;&#x8F7D;&#x6027;&#x80FD;&#x5982;&#x4F55;&#x4E86;&#x3002;</p>
<p>&#x53E6;&#x5916;&#xFF0C;&#x901A;&#x8FC7; <code>window.performance.getEntriesByType(&apos;resource&apos;)</code> &#x8FD9;&#x4E2A;&#x65B9;&#x6CD5;&#xFF0C;&#x6211;&#x4EEC;&#x8FD8;&#x53EF;&#x4EE5;&#x83B7;&#x53D6;&#x76F8;&#x5173;&#x8D44;&#x6E90;&#xFF08;js&#x3001;css&#x3001;img...&#xFF09;&#x7684;&#x52A0;&#x8F7D;&#x65F6;&#x95F4;&#xFF0C;&#x5B83;&#x4F1A;&#x8FD4;&#x56DE;&#x9875;&#x9762;&#x5F53;&#x524D;&#x6240;&#x52A0;&#x8F7D;&#x7684;&#x6240;&#x6709;&#x8D44;&#x6E90;&#x3002;</p>
<p><img src="https://github.com/woai3c/Front-end-articles/blob/master/imgs/monitor3.png" alt="&#x5728;&#x8FD9;&#x91CC;&#x63D2;&#x5165;&#x56FE;&#x7247;&#x63CF;&#x8FF0;"></p>
<p>&#x5B83;&#x4E00;&#x822C;&#x5305;&#x62EC;&#x4EE5;&#x4E0B;&#x51E0;&#x4E2A;&#x7C7B;&#x578B;</p>
<ul>
<li>sciprt</li>
<li>link</li>
<li>img</li>
<li>css</li>
<li>fetch</li>
<li>other</li>
<li>xmlhttprequest</li>
</ul>
<p>&#x6211;&#x4EEC;&#x53EA;&#x9700;&#x7528;&#x5230;&#x4EE5;&#x4E0B;&#x51E0;&#x4E2A;&#x4FE1;&#x606F;</p>
<pre><code class="lang-js"><span class="hljs-comment">// &#x8D44;&#x6E90;&#x7684;&#x540D;&#x79F0;</span>
name: item.name,
<span class="hljs-comment">// &#x8D44;&#x6E90;&#x52A0;&#x8F7D;&#x8017;&#x65F6;</span>
duration: item.duration.toFixed(<span class="hljs-number">2</span>),
<span class="hljs-comment">// &#x8D44;&#x6E90;&#x5927;&#x5C0F;</span>
size: item.transferSize,
<span class="hljs-comment">// &#x8D44;&#x6E90;&#x6240;&#x7528;&#x534F;&#x8BAE;</span>
protocol: item.nextHopProtocol,
</code></pre>
<p>&#x73B0;&#x5728;&#xFF0C;&#x5199;&#x51E0;&#x884C;&#x4EE3;&#x7801;&#x6765;&#x6536;&#x96C6;&#x8FD9;&#x4E9B;&#x6570;&#x636E;&#x3002;</p>
<pre><code class="lang-js"><span class="hljs-comment">// &#x6536;&#x96C6;&#x6027;&#x80FD;&#x4FE1;&#x606F;</span>
<span class="hljs-keyword">const</span> getPerformance = () =&gt; {
    <span class="hljs-keyword">if</span> (!<span class="hljs-built_in">window</span>.performance) <span class="hljs-keyword">return</span>
    <span class="hljs-keyword">const</span> timing = <span class="hljs-built_in">window</span>.performance.timing
    <span class="hljs-keyword">const</span> performance = {
        <span class="hljs-comment">// &#x91CD;&#x5B9A;&#x5411;&#x8017;&#x65F6;</span>
        redirect: timing.redirectEnd - timing.redirectStart,
        <span class="hljs-comment">// &#x767D;&#x5C4F;&#x65F6;&#x95F4;</span>
        whiteScreen: whiteScreen,
        <span class="hljs-comment">// DOM &#x6E32;&#x67D3;&#x8017;&#x65F6;</span>
        dom: timing.domComplete - timing.domLoading,
        <span class="hljs-comment">// &#x9875;&#x9762;&#x52A0;&#x8F7D;&#x8017;&#x65F6;</span>
        load: timing.loadEventEnd - timing.navigationStart,
        <span class="hljs-comment">// &#x9875;&#x9762;&#x5378;&#x8F7D;&#x8017;&#x65F6;</span>
        unload: timing.unloadEventEnd - timing.unloadEventStart,
        <span class="hljs-comment">// &#x8BF7;&#x6C42;&#x8017;&#x65F6;</span>
        request: timing.responseEnd - timing.requestStart,
        <span class="hljs-comment">// &#x83B7;&#x53D6;&#x6027;&#x80FD;&#x4FE1;&#x606F;&#x65F6;&#x5F53;&#x524D;&#x65F6;&#x95F4;</span>
        time: <span class="hljs-keyword">new</span> <span class="hljs-built_in">Date</span>().getTime(),
    }

    <span class="hljs-keyword">return</span> performance
}

<span class="hljs-comment">// &#x83B7;&#x53D6;&#x8D44;&#x6E90;&#x4FE1;&#x606F;</span>
<span class="hljs-keyword">const</span> getResources = () =&gt; {
    <span class="hljs-keyword">if</span> (!<span class="hljs-built_in">window</span>.performance) <span class="hljs-keyword">return</span>
    <span class="hljs-keyword">const</span> data = <span class="hljs-built_in">window</span>.performance.getEntriesByType(<span class="hljs-string">&apos;resource&apos;</span>)
    <span class="hljs-keyword">const</span> resource = {
        xmlhttprequest: [],
        css: [],
        other: [],
        script: [],
        img: [],
        link: [],
        fetch: [],
        <span class="hljs-comment">// &#x83B7;&#x53D6;&#x8D44;&#x6E90;&#x4FE1;&#x606F;&#x65F6;&#x5F53;&#x524D;&#x65F6;&#x95F4;</span>
        time: <span class="hljs-keyword">new</span> <span class="hljs-built_in">Date</span>().getTime(),
    }

    data.forEach(item =&gt; {
        <span class="hljs-keyword">const</span> arry = resource[item.initiatorType]
        arry &amp;&amp; arry.push({
            <span class="hljs-comment">// &#x8D44;&#x6E90;&#x7684;&#x540D;&#x79F0;</span>
            name: item.name,
            <span class="hljs-comment">// &#x8D44;&#x6E90;&#x52A0;&#x8F7D;&#x8017;&#x65F6;</span>
            duration: item.duration.toFixed(<span class="hljs-number">2</span>),
            <span class="hljs-comment">// &#x8D44;&#x6E90;&#x5927;&#x5C0F;</span>
            size: item.transferSize,
            <span class="hljs-comment">// &#x8D44;&#x6E90;&#x6240;&#x7528;&#x534F;&#x8BAE;</span>
            protocol: item.nextHopProtocol,
        })
    })

    <span class="hljs-keyword">return</span> resource
}
</code></pre>
<h4 id="&#x5C0F;&#x7ED3;">&#x5C0F;&#x7ED3;</h4>
<p>&#x901A;&#x8FC7;&#x5BF9;&#x6027;&#x80FD;&#x53CA;&#x8D44;&#x6E90;&#x4FE1;&#x606F;&#x7684;&#x89E3;&#x8BFB;&#xFF0C;&#x6211;&#x4EEC;&#x53EF;&#x4EE5;&#x5224;&#x65AD;&#x51FA;&#x9875;&#x9762;&#x52A0;&#x8F7D;&#x6162;&#x6709;&#x4EE5;&#x4E0B;&#x51E0;&#x4E2A;&#x539F;&#x56E0;&#xFF1A;</p>
<ol>
<li>&#x8D44;&#x6E90;&#x8FC7;&#x591A;</li>
<li>&#x7F51;&#x901F;&#x8FC7;&#x6162;</li>
<li>DOM&#x5143;&#x7D20;&#x8FC7;&#x591A;</li>
</ol>
<p>&#x9664;&#x4E86;&#x7528;&#x6237;&#x7F51;&#x901F;&#x8FC7;&#x6162;&#xFF0C;&#x6211;&#x4EEC;&#x6CA1;&#x529E;&#x6CD5;&#x4E4B;&#x5916;&#xFF0C;&#x5176;&#x4ED6;&#x4E24;&#x4E2A;&#x539F;&#x56E0;&#x90FD;&#x662F;&#x6709;&#x529E;&#x6CD5;&#x89E3;&#x51B3;&#x7684;&#xFF0C;&#x6027;&#x80FD;&#x4F18;&#x5316;&#x7684;&#x6587;&#x7AE0;&#x548C;&#x4E66;&#x7C4D;&#x7F51;&#x4E0A;&#x5DF2;&#x7ECF;&#x6709;&#x5F88;&#x591A;&#x4E86;&#xFF0C;&#x6709;&#x5174;&#x8DA3;&#x53EF;&#x81EA;&#x884C;&#x67E5;&#x627E;&#x8D44;&#x6599;&#x4E86;&#x89E3;&#x3002;</p>
<h3 id="&#x9519;&#x8BEF;&#x6570;&#x636E;&#x91C7;&#x96C6;">&#x9519;&#x8BEF;&#x6570;&#x636E;&#x91C7;&#x96C6;</h3>
<p>&#x901A;&#x8FC7;&#x8FD9;&#x51E0;&#x5929;&#x7684;&#x8D44;&#x6599;&#x67E5;&#x627E;&#xFF0C;&#x4E86;&#x89E3;&#x5230;&#x73B0;&#x5728;&#x80FD;&#x6355;&#x6349;&#x7684;&#x9519;&#x8BEF;&#x6709;&#x4E09;&#x79CD;&#x3002;</p>
<ol>
<li>&#x8D44;&#x6E90;&#x52A0;&#x8F7D;&#x9519;&#x8BEF;</li>
<li>js &#x6267;&#x884C;&#x9519;&#x8BEF;</li>
<li>promise &#x9519;&#x8BEF;</li>
</ol>
<p><strong>1</strong> &#x901A;&#x8FC7; <code>addEventListener(&apos;error&apos;, callback, true)</code> &#x5728;&#x6355;&#x83B7;&#x9636;&#x6BB5;&#x6355;&#x6349;&#x8D44;&#x6E90;&#x52A0;&#x8F7D;&#x5931;&#x8D25;&#x9519;&#x8BEF;&#x3002;</p>
<p><strong>2</strong> &#x901A;&#x8FC7; <code>window.onerror</code> &#x6355;&#x6349; js &#x9519;&#x8BEF;&#x3002;</p>
<p><strong>3</strong> &#x901A;&#x8FC7; <code>addEventListener(&apos;unhandledrejection&apos;, callback)</code>&#x6355;&#x6349; promise &#x9519;&#x8BEF;&#xFF0C;&#x4F46;&#x662F;&#x6CA1;&#x6709;&#x53D1;&#x751F;&#x9519;&#x8BEF;&#x7684;&#x884C;&#x6570;&#xFF0C;&#x5217;&#x6570;&#x7B49;&#x4FE1;&#x606F;&#xFF0C;&#x53EA;&#x80FD;&#x624B;&#x52A8;&#x629B;&#x51FA;&#x76F8;&#x5173;&#x9519;&#x8BEF;&#x4FE1;&#x606F;&#x3002;</p>
<p>&#x6211;&#x4EEC;&#x53EF;&#x4EE5;&#x5EFA;&#x4E00;&#x4E2A;&#x9519;&#x8BEF;&#x6570;&#x7EC4;&#x53D8;&#x91CF; <code>errors</code> &#x5728;&#x9519;&#x8BEF;&#x53D1;&#x751F;&#x65F6;&#xFF0C;&#x5C06;&#x9519;&#x8BEF;&#x7684;&#x76F8;&#x5173;&#x4FE1;&#x606F;&#x6DFB;&#x52A0;&#x5230;&#x6570;&#x7EC4;&#xFF0C;&#x7136;&#x540E;&#x5728;&#x67D0;&#x4E2A;&#x9636;&#x6BB5;&#x7EDF;&#x4E00;&#x4E0A;&#x62A5;&#xFF0C;&#x5177;&#x4F53;&#x5982;&#x4F55;&#x64CD;&#x4F5C;&#x8BF7;&#x770B;&#x4EE3;&#x7801;</p>
<pre><code class="lang-js"><span class="hljs-comment">// &#x6355;&#x83B7;&#x8D44;&#x6E90;&#x52A0;&#x8F7D;&#x5931;&#x8D25;&#x9519;&#x8BEF; js css img...</span>
addEventListener(<span class="hljs-string">&apos;error&apos;</span>, e =&gt; {
    <span class="hljs-keyword">const</span> target = e.target
    <span class="hljs-keyword">if</span> (target != <span class="hljs-built_in">window</span>) {
        monitor.errors.push({
            type: target.localName,
            url: target.src || target.href,
            msg: (target.src || target.href) + <span class="hljs-string">&apos; is load error&apos;</span>,
            <span class="hljs-comment">// &#x9519;&#x8BEF;&#x53D1;&#x751F;&#x7684;&#x65F6;&#x95F4;</span>
            time: <span class="hljs-keyword">new</span> <span class="hljs-built_in">Date</span>().getTime(),
        })
    }
}, <span class="hljs-literal">true</span>)

<span class="hljs-comment">// &#x76D1;&#x542C; js &#x9519;&#x8BEF;</span>
<span class="hljs-built_in">window</span>.onerror = <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">msg, url, row, col, error</span>) </span>{
    monitor.errors.push({
        type: <span class="hljs-string">&apos;javascript&apos;</span>,
        row: row,
        col: col,
        msg: error &amp;&amp; error.stack? error.stack : msg,
        url: url,
        <span class="hljs-comment">// &#x9519;&#x8BEF;&#x53D1;&#x751F;&#x7684;&#x65F6;&#x95F4;</span>
        time: <span class="hljs-keyword">new</span> <span class="hljs-built_in">Date</span>().getTime(),
    })
}

<span class="hljs-comment">// &#x76D1;&#x542C; promise &#x9519;&#x8BEF; &#x7F3A;&#x70B9;&#x662F;&#x83B7;&#x53D6;&#x4E0D;&#x5230;&#x884C;&#x6570;&#x6570;&#x636E;</span>
addEventListener(<span class="hljs-string">&apos;unhandledrejection&apos;</span>, e =&gt; {
    monitor.errors.push({
        type: <span class="hljs-string">&apos;promise&apos;</span>,
        msg: (e.reason &amp;&amp; e.reason.msg) || e.reason || <span class="hljs-string">&apos;&apos;</span>,
        <span class="hljs-comment">// &#x9519;&#x8BEF;&#x53D1;&#x751F;&#x7684;&#x65F6;&#x95F4;</span>
        time: <span class="hljs-keyword">new</span> <span class="hljs-built_in">Date</span>().getTime(),
    })
})
</code></pre>
<h4 id="&#x5C0F;&#x7ED3;">&#x5C0F;&#x7ED3;</h4>
<p>&#x901A;&#x8FC7;&#x9519;&#x8BEF;&#x6536;&#x96C6;&#xFF0C;&#x53EF;&#x4EE5;&#x4E86;&#x89E3;&#x5230;&#x7F51;&#x7AD9;&#x9519;&#x8BEF;&#x53D1;&#x751F;&#x7684;&#x7C7B;&#x578B;&#x53CA;&#x6570;&#x91CF;&#xFF0C;&#x4ECE;&#x800C;&#x53EF;&#x4EE5;&#x505A;&#x76F8;&#x5E94;&#x7684;&#x8C03;&#x6574;&#xFF0C;&#x4EE5;&#x51CF;&#x5C11;&#x9519;&#x8BEF;&#x53D1;&#x751F;&#x3002;
&#x5B8C;&#x6574;&#x4EE3;&#x7801;&#x548C;DEMO&#x4F1A;&#x5728;&#x6587;&#x7AE0;&#x672B;&#x5C3E;&#x653E;&#x51FA;&#xFF0C;&#x5927;&#x5BB6;&#x53EF;&#x4EE5;&#x590D;&#x5236;&#x4EE3;&#x7801;&#xFF08;HTML&#x6587;&#x4EF6;&#xFF09;&#x5728;&#x672C;&#x5730;&#x6D4B;&#x8BD5;&#x4E00;&#x4E0B;&#x3002;</p>
<h2 id="&#x6570;&#x636E;&#x4E0A;&#x62A5;">&#x6570;&#x636E;&#x4E0A;&#x62A5;</h2>
<h3 id="&#x6027;&#x80FD;&#x6570;&#x636E;&#x4E0A;&#x62A5;">&#x6027;&#x80FD;&#x6570;&#x636E;&#x4E0A;&#x62A5;</h3>
<p>&#x6027;&#x80FD;&#x6570;&#x636E;&#x53EF;&#x4EE5;&#x5728;&#x9875;&#x9762;&#x52A0;&#x8F7D;&#x5B8C;&#x4E4B;&#x540E;&#x4E0A;&#x62A5;&#xFF0C;&#x5C3D;&#x91CF;&#x4E0D;&#x8981;&#x5BF9;&#x9875;&#x9762;&#x6027;&#x80FD;&#x9020;&#x6210;&#x5F71;&#x54CD;&#x3002;</p>
<pre><code class="lang-js"><span class="hljs-built_in">window</span>.onload = () =&gt; {
    <span class="hljs-comment">// &#x5728;&#x6D4F;&#x89C8;&#x5668;&#x7A7A;&#x95F2;&#x65F6;&#x95F4;&#x83B7;&#x53D6;&#x6027;&#x80FD;&#x53CA;&#x8D44;&#x6E90;&#x4FE1;&#x606F;</span>
    <span class="hljs-comment">// https://developer.mozilla.org/zh-CN/docs/Web/API/Window/requestIdleCallback</span>
    <span class="hljs-keyword">if</span> (<span class="hljs-built_in">window</span>.requestIdleCallback) {
        <span class="hljs-built_in">window</span>.requestIdleCallback(() =&gt; {
            monitor.performance = getPerformance()
            monitor.resources = getResources()
        })
    } <span class="hljs-keyword">else</span> {
        setTimeout(() =&gt; {
            monitor.performance = getPerformance()
            monitor.resources = getResources()
        }, <span class="hljs-number">0</span>)
    }
}
</code></pre>
<p>&#x5F53;&#x7136;&#xFF0C;&#x4F60;&#x4E5F;&#x53EF;&#x4EE5;&#x8BBE;&#x4E00;&#x4E2A;&#x5B9A;&#x65F6;&#x5668;&#xFF0C;&#x5FAA;&#x73AF;&#x4E0A;&#x62A5;&#x3002;&#x4E0D;&#x8FC7;&#x6BCF;&#x6B21;&#x4E0A;&#x62A5;&#x6700;&#x597D;&#x505A;&#x4E00;&#x4E0B;&#x5BF9;&#x6BD4;&#x53BB;&#x91CD;&#x518D;&#x4E0A;&#x62A5;&#xFF0C;&#x907F;&#x514D;&#x540C;&#x6837;&#x7684;&#x6570;&#x636E;&#x91CD;&#x590D;&#x4E0A;&#x62A5;&#x3002;</p>
<h3 id="&#x9519;&#x8BEF;&#x6570;&#x636E;&#x4E0A;&#x62A5;">&#x9519;&#x8BEF;&#x6570;&#x636E;&#x4E0A;&#x62A5;</h3>
<p>&#x6211;&#x5728;DEMO&#x91CC;&#x63D0;&#x4F9B;&#x7684;&#x4EE3;&#x7801;&#xFF0C;&#x662F;&#x7528;&#x4E00;&#x4E2A; <code>errors</code> &#x6570;&#x7EC4;&#x6536;&#x96C6;&#x6240;&#x6709;&#x7684;&#x9519;&#x8BEF;&#xFF0C;&#x518D;&#x5728;&#x67D0;&#x4E00;&#x9636;&#x6BB5;&#x7EDF;&#x4E00;&#x4E0A;&#x62A5;&#xFF08;&#x5EF6;&#x65F6;&#x4E0A;&#x62A5;&#xFF09;&#x3002;
&#x5176;&#x5B9E;&#xFF0C;&#x4E5F;&#x53EF;&#x4EE5;&#x6539;&#x6210;&#x5728;&#x9519;&#x8BEF;&#x53D1;&#x751F;&#x65F6;&#x4E0A;&#x62A5;&#xFF08;&#x5373;&#x65F6;&#x4E0A;&#x62A5;&#xFF09;&#x3002;&#x8FD9;&#x6837;&#x53EF;&#x4EE5;&#x907F;&#x514D;&#x5728;&#x6536;&#x96C6;&#x5B8C;&#x9519;&#x8BEF;&#x5EF6;&#x65F6;&#x4E0A;&#x62A5;&#x8FD8;&#x6CA1;&#x89E6;&#x53D1;&#xFF0C;&#x7528;&#x6237;&#x5374;&#x5DF2;&#x7ECF;&#x5173;&#x6389;&#x7F51;&#x9875;&#x5BFC;&#x81F4;&#x9519;&#x8BEF;&#x6570;&#x636E;&#x4E22;&#x5931;&#x7684;&#x95EE;&#x9898;&#x3002;</p>
<pre><code class="lang-js"><span class="hljs-comment">// &#x76D1;&#x542C; js &#x9519;&#x8BEF;</span>
<span class="hljs-built_in">window</span>.onerror = <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">msg, url, row, col, error</span>) </span>{
    <span class="hljs-keyword">const</span> data = {
        type: <span class="hljs-string">&apos;javascript&apos;</span>,
        row: row,
        col: col,
        msg: error &amp;&amp; error.stack? error.stack : msg,
        url: url,
        <span class="hljs-comment">// &#x9519;&#x8BEF;&#x53D1;&#x751F;&#x7684;&#x65F6;&#x95F4;</span>
        time: <span class="hljs-keyword">new</span> <span class="hljs-built_in">Date</span>().getTime(),
    }

    <span class="hljs-comment">// &#x5373;&#x65F6;&#x4E0A;&#x62A5;</span>
    axios.post({ url: <span class="hljs-string">&apos;xxx&apos;</span>, data, })
}
</code></pre>
<h2 id="&#x6269;&#x5C55;">&#x6269;&#x5C55;</h2>
<h3 id="spa">SPA</h3>
<p><code>window.performance</code> API &#x662F;&#x6709;&#x7F3A;&#x70B9;&#x7684;&#xFF0C;&#x5728; SPA &#x5207;&#x6362;&#x8DEF;&#x7531;&#x65F6;&#xFF0C;<code>window.performance.timing</code> &#x7684;&#x6570;&#x636E;&#x4E0D;&#x4F1A;&#x66F4;&#x65B0;&#x3002;
&#x6240;&#x4EE5;&#x6211;&#x4EEC;&#x9700;&#x8981;&#x53E6;&#x60F3;&#x529E;&#x6CD5;&#x6765;&#x7EDF;&#x8BA1;&#x5207;&#x6362;&#x8DEF;&#x7531;&#x5230;&#x52A0;&#x8F7D;&#x5B8C;&#x6210;&#x7684;&#x65F6;&#x95F4;&#x3002;</p>
<p>&#x62FF; Vue &#x4E3E;&#x4F8B;&#xFF0C;&#x4E00;&#x4E2A;&#x53EF;&#x884C;&#x7684;&#x529E;&#x6CD5;&#x5C31;&#x662F;&#x5207;&#x6362;&#x8DEF;&#x7531;&#x65F6;&#xFF0C;&#x5728;&#x8DEF;&#x7531;&#x7684;&#x5168;&#x5C40;&#x524D;&#x7F6E;&#x5B88;&#x536B; <code>beforeEach</code> &#x91CC;&#x83B7;&#x53D6;&#x5F00;&#x59CB;&#x65F6;&#x95F4;&#xFF0C;&#x5728;&#x7EC4;&#x4EF6;&#x7684; <code>mounted</code> &#x94A9;&#x5B50;&#x91CC;&#x6267;&#x884C; <code>vm.$nextTick</code> &#x51FD;&#x6570;&#x6765;&#x83B7;&#x53D6;&#x7EC4;&#x4EF6;&#x7684;&#x6E32;&#x67D3;&#x5B8C;&#x6BD5;&#x65F6;&#x95F4;&#x3002;</p>
<pre><code class="lang-js">router.beforeEach((to, <span class="hljs-keyword">from</span>, next) =&gt; {
    store.commit(<span class="hljs-string">&apos;setPageLoadedStartTime&apos;</span>, <span class="hljs-keyword">new</span> <span class="hljs-built_in">Date</span>())
})
</code></pre>
<pre><code class="lang-js">mounted() {
    <span class="hljs-keyword">this</span>.$nextTick(() =&gt; {
        <span class="hljs-keyword">this</span>.$store.commit(<span class="hljs-string">&apos;setPageLoadedTime&apos;</span>, <span class="hljs-keyword">new</span> <span class="hljs-built_in">Date</span>() - <span class="hljs-keyword">this</span>.$store.state.pageLoadedStartTime)
    })
}
</code></pre>
<p>&#x9664;&#x4E86;&#x6027;&#x80FD;&#x548C;&#x9519;&#x8BEF;&#x76D1;&#x63A7;&#xFF0C;&#x5176;&#x5B9E;&#x6211;&#x4EEC;&#x8FD8;&#x53EF;&#x4EE5;&#x505A;&#x5F97;&#x66F4;&#x591A;&#x3002;</p>
<h3 id="&#x7528;&#x6237;&#x4FE1;&#x606F;&#x6536;&#x96C6;">&#x7528;&#x6237;&#x4FE1;&#x606F;&#x6536;&#x96C6;</h3>
<h4 id="navigator">navigator</h4>
<p>&#x4F7F;&#x7528; <code>window.navigator</code> &#x53EF;&#x4EE5;&#x6536;&#x96C6;&#x5230;&#x7528;&#x6237;&#x7684;&#x8BBE;&#x5907;&#x4FE1;&#x606F;&#xFF0C;&#x64CD;&#x4F5C;&#x7CFB;&#x7EDF;&#xFF0C;&#x6D4F;&#x89C8;&#x5668;&#x4FE1;&#x606F;...</p>
<h4 id="uv&#xFF08;unique-visitor&#xFF09;">UV&#xFF08;Unique visitor&#xFF09;</h4>
<p>&#x662F;&#x6307;&#x901A;&#x8FC7;&#x4E92;&#x8054;&#x7F51;&#x8BBF;&#x95EE;&#x3001;&#x6D4F;&#x89C8;&#x8FD9;&#x4E2A;&#x7F51;&#x9875;&#x7684;&#x81EA;&#x7136;&#x4EBA;&#x3002;&#x8BBF;&#x95EE;&#x60A8;&#x7F51;&#x7AD9;&#x7684;&#x4E00;&#x53F0;&#x7535;&#x8111;&#x5BA2;&#x6237;&#x7AEF;&#x4E3A;&#x4E00;&#x4E2A;&#x8BBF;&#x5BA2;&#x3002;00:00-24:00&#x5185;&#x76F8;&#x540C;&#x7684;&#x5BA2;&#x6237;&#x7AEF;&#x53EA;&#x88AB;&#x8BA1;&#x7B97;&#x4E00;&#x6B21;&#x3002;&#x4E00;&#x5929;&#x5185;&#x540C;&#x4E2A;&#x8BBF;&#x5BA2;&#x591A;&#x6B21;&#x8BBF;&#x95EE;&#x4EC5;&#x8BA1;&#x7B97;&#x4E00;&#x4E2A;UV&#x3002;
&#x5728;&#x7528;&#x6237;&#x8BBF;&#x95EE;&#x7F51;&#x7AD9;&#x65F6;&#xFF0C;&#x53EF;&#x4EE5;&#x751F;&#x6210;&#x4E00;&#x4E2A;&#x968F;&#x673A;&#x5B57;&#x7B26;&#x4E32;+&#x65F6;&#x95F4;&#x65E5;&#x671F;&#xFF0C;&#x4FDD;&#x5B58;&#x5728;&#x672C;&#x5730;&#x3002;&#x5728;&#x7F51;&#x9875;&#x53D1;&#x751F;&#x8BF7;&#x6C42;&#x65F6;&#xFF08;&#x5982;&#x679C;&#x8D85;&#x8FC7;&#x5F53;&#x5929;24&#x5C0F;&#x65F6;&#xFF0C;&#x5219;&#x91CD;&#x65B0;&#x751F;&#x6210;&#xFF09;&#xFF0C;&#x628A;&#x8FD9;&#x4E9B;&#x53C2;&#x6570;&#x4F20;&#x5230;&#x540E;&#x7AEF;&#xFF0C;&#x540E;&#x7AEF;&#x5229;&#x7528;&#x8FD9;&#x4E9B;&#x4FE1;&#x606F;&#x751F;&#x6210; UV &#x7EDF;&#x8BA1;&#x62A5;&#x544A;&#x3002;</p>
<h4 id="pv&#xFF08;page-view&#xFF09;">PV&#xFF08;Page View&#xFF09;</h4>
<p>  &#x5373;&#x9875;&#x9762;&#x6D4F;&#x89C8;&#x91CF;&#x6216;&#x70B9;&#x51FB;&#x91CF;&#xFF0C;&#x7528;&#x6237;&#x6BCF;1&#x6B21;&#x5BF9;&#x7F51;&#x7AD9;&#x4E2D;&#x7684;&#x6BCF;&#x4E2A;&#x7F51;&#x9875;&#x8BBF;&#x95EE;&#x5747;&#x88AB;&#x8BB0;&#x5F55;1&#x4E2A;PV&#x3002;&#x7528;&#x6237;&#x5BF9;&#x540C;&#x4E00;&#x9875;&#x9762;&#x7684;&#x591A;&#x6B21;&#x8BBF;&#x95EE;&#xFF0C;&#x8BBF;&#x95EE;&#x91CF;&#x7D2F;&#x8BA1;&#xFF0C;&#x7528;&#x4EE5;&#x8861;&#x91CF;&#x7F51;&#x7AD9;&#x7528;&#x6237;&#x8BBF;&#x95EE;&#x7684;&#x7F51;&#x9875;&#x6570;&#x91CF;&#x3002;</p>
<h4 id="&#x9875;&#x9762;&#x505C;&#x7559;&#x65F6;&#x95F4;">&#x9875;&#x9762;&#x505C;&#x7559;&#x65F6;&#x95F4;</h4>
<p><strong>&#x4F20;&#x7EDF;&#x7F51;&#x7AD9;</strong>
&#x7528;&#x6237;&#x5728;&#x8FDB;&#x5165; A &#x9875;&#x9762;&#x65F6;&#xFF0C;&#x901A;&#x8FC7;&#x540E;&#x53F0;&#x8BF7;&#x6C42;&#x628A;&#x7528;&#x6237;&#x8FDB;&#x5165;&#x9875;&#x9762;&#x7684;&#x65F6;&#x95F4;&#x634E;&#x4E0A;&#x3002;&#x8FC7;&#x4E86; 10 &#x5206;&#x949F;&#xFF0C;&#x7528;&#x6237;&#x8FDB;&#x5165; B &#x9875;&#x9762;&#xFF0C;&#x8FD9;&#x65F6;&#x540E;&#x53F0;&#x53EF;&#x4EE5;&#x901A;&#x8FC7;&#x63A5;&#x53E3;&#x634E;&#x5E26;&#x7684;&#x53C2;&#x6570;&#x53EF;&#x4EE5;&#x5224;&#x65AD;&#x51FA;&#x7528;&#x6237;&#x5728; A &#x9875;&#x9762;&#x505C;&#x7559;&#x4E86; 10 &#x5206;&#x949F;&#x3002;
<strong>SPA</strong>
&#x53EF;&#x4EE5;&#x5229;&#x7528; router &#x6765;&#x83B7;&#x53D6;&#x7528;&#x6237;&#x505C;&#x7559;&#x65F6;&#x95F4;&#xFF0C;&#x62FF; Vue &#x4E3E;&#x4F8B;&#xFF0C;&#x901A;&#x8FC7; <code>router.beforeEach</code> <code>destroyed</code> &#x8FD9;&#x4E24;&#x4E2A;&#x94A9;&#x5B50;&#x51FD;&#x6570;&#x6765;&#x83B7;&#x53D6;&#x7528;&#x6237;&#x505C;&#x7559;&#x8BE5;&#x8DEF;&#x7531;&#x7EC4;&#x4EF6;&#x7684;&#x65F6;&#x95F4;&#x3002;</p>
<h4 id="&#x6D4F;&#x89C8;&#x6DF1;&#x5EA6;">&#x6D4F;&#x89C8;&#x6DF1;&#x5EA6;</h4>
<p>&#x901A;&#x8FC7; <code>document.documentElement.scrollTop</code> &#x5C5E;&#x6027;&#x4EE5;&#x53CA;&#x5C4F;&#x5E55;&#x9AD8;&#x5EA6;&#xFF0C;&#x53EF;&#x4EE5;&#x5224;&#x65AD;&#x7528;&#x6237;&#x662F;&#x5426;&#x6D4F;&#x89C8;&#x5B8C;&#x7F51;&#x7AD9;&#x5185;&#x5BB9;&#x3002;</p>
<h4 id="&#x9875;&#x9762;&#x8DF3;&#x8F6C;&#x6765;&#x6E90;">&#x9875;&#x9762;&#x8DF3;&#x8F6C;&#x6765;&#x6E90;</h4>
<p>&#x901A;&#x8FC7; <code>document.referrer</code> &#x5C5E;&#x6027;&#xFF0C;&#x53EF;&#x4EE5;&#x77E5;&#x9053;&#x7528;&#x6237;&#x662F;&#x4ECE;&#x54EA;&#x4E2A;&#x7F51;&#x7AD9;&#x8DF3;&#x8F6C;&#x800C;&#x6765;&#x3002;</p>
<h3 id="&#x5C0F;&#x7ED3;">&#x5C0F;&#x7ED3;</h3>
<p>&#x901A;&#x8FC7;&#x5206;&#x6790;&#x7528;&#x6237;&#x6570;&#x636E;&#xFF0C;&#x6211;&#x4EEC;&#x53EF;&#x4EE5;&#x4E86;&#x89E3;&#x5230;&#x7528;&#x6237;&#x7684;&#x6D4F;&#x89C8;&#x4E60;&#x60EF;&#x3001;&#x7231;&#x597D;&#x7B49;&#x7B49;&#x4FE1;&#x606F;&#xFF0C;&#x60F3;&#x60F3;&#x771F;&#x662F;&#x6050;&#x6016;&#xFF0C;&#x6BEB;&#x65E0;&#x9690;&#x79C1;&#x53EF;&#x8A00;&#x3002;</p>
<h2 id="demo">DEMO</h2>
<pre><code class="lang-html"><span class="hljs-meta">&lt;!DOCTYPE html&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">html</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">head</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">meta</span> <span class="hljs-attr">charset</span>=<span class="hljs-string">&quot;UTF-8&quot;</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">meta</span> <span class="hljs-attr">name</span>=<span class="hljs-string">&quot;viewport&quot;</span> <span class="hljs-attr">content</span>=<span class="hljs-string">&quot;width=device-width, initial-scale=1.0&quot;</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">meta</span> <span class="hljs-attr">http-equiv</span>=<span class="hljs-string">&quot;X-UA-Compatible&quot;</span> <span class="hljs-attr">content</span>=<span class="hljs-string">&quot;ie=edge&quot;</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">script</span>&gt;</span><span class="javascript">
        <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">monitorInit</span>(<span class="hljs-params"></span>) </span>{
            <span class="hljs-keyword">const</span> monitor = {
                <span class="hljs-comment">// &#x6570;&#x636E;&#x4E0A;&#x4F20;&#x5730;&#x5740;</span>
                url: <span class="hljs-string">&apos;&apos;</span>,
                <span class="hljs-comment">// &#x6027;&#x80FD;&#x4FE1;&#x606F;</span>
                performance: {},
                <span class="hljs-comment">// &#x8D44;&#x6E90;&#x4FE1;&#x606F;</span>
                resources: {},
                <span class="hljs-comment">// &#x9519;&#x8BEF;&#x4FE1;&#x606F;</span>
                errors: [],
                <span class="hljs-comment">// &#x7528;&#x6237;&#x4FE1;&#x606F;</span>
                user: {
                    <span class="hljs-comment">// &#x5C4F;&#x5E55;&#x5BBD;&#x5EA6;</span>
                    screen: screen.width,
                    <span class="hljs-comment">// &#x5C4F;&#x5E55;&#x9AD8;&#x5EA6;</span>
                    height: screen.height,
                    <span class="hljs-comment">// &#x6D4F;&#x89C8;&#x5668;&#x5E73;&#x53F0;</span>
                    platform: navigator.platform,
                    <span class="hljs-comment">// &#x6D4F;&#x89C8;&#x5668;&#x7684;&#x7528;&#x6237;&#x4EE3;&#x7406;&#x4FE1;&#x606F;</span>
                    userAgent: navigator.userAgent,
                    <span class="hljs-comment">// &#x6D4F;&#x89C8;&#x5668;&#x7528;&#x6237;&#x754C;&#x9762;&#x7684;&#x8BED;&#x8A00;</span>
                    language: navigator.language,
                },
                <span class="hljs-comment">// &#x624B;&#x52A8;&#x6DFB;&#x52A0;&#x9519;&#x8BEF;</span>
                addError(error) {
                    <span class="hljs-keyword">const</span> obj = {}
                    <span class="hljs-keyword">const</span> { type, msg, url, row, col } = error
                    <span class="hljs-keyword">if</span> (type) obj.type = type
                    <span class="hljs-keyword">if</span> (msg) obj.msg = msg
                    <span class="hljs-keyword">if</span> (url) obj.url = url
                    <span class="hljs-keyword">if</span> (row) obj.row = row
                    <span class="hljs-keyword">if</span> (col) obj.col = col
                    obj.time = <span class="hljs-keyword">new</span> <span class="hljs-built_in">Date</span>().getTime()
                    monitor.errors.push(obj)
                },
                <span class="hljs-comment">// &#x91CD;&#x7F6E; monitor &#x5BF9;&#x8C61;</span>
                reset() {
                    <span class="hljs-built_in">window</span>.performance &amp;&amp; <span class="hljs-built_in">window</span>.performance.clearResourceTimings()
                    monitor.performance = getPerformance()
                    monitor.resources = getResources()
                    monitor.errors = []
                },
                <span class="hljs-comment">// &#x6E05;&#x7A7A; error &#x4FE1;&#x606F;</span>
                clearError() {
                    monitor.errors = []
                },
                <span class="hljs-comment">// &#x4E0A;&#x4F20;&#x76D1;&#x63A7;&#x6570;&#x636E;</span>
                upload() {
                    <span class="hljs-comment">// &#x81EA;&#x5B9A;&#x4E49;&#x4E0A;&#x4F20;</span>
                    <span class="hljs-comment">// axios.post({</span>
                    <span class="hljs-comment">//     url: monitor.url,</span>
                    <span class="hljs-comment">//     data: {</span>
                    <span class="hljs-comment">//         performance,</span>
                    <span class="hljs-comment">//         resources,</span>
                    <span class="hljs-comment">//         errors,</span>
                    <span class="hljs-comment">//         user,</span>
                    <span class="hljs-comment">//     }</span>
                    <span class="hljs-comment">// })</span>
                },
                <span class="hljs-comment">// &#x8BBE;&#x7F6E;&#x6570;&#x636E;&#x4E0A;&#x4F20;&#x5730;&#x5740;</span>
                setURL(url) {
                    monitor.url = url
                },
            }

            <span class="hljs-comment">// &#x83B7;&#x53D6;&#x6027;&#x80FD;&#x4FE1;&#x606F;</span>
            <span class="hljs-keyword">const</span> getPerformance = () =&gt; {
                <span class="hljs-keyword">if</span> (!<span class="hljs-built_in">window</span>.performance) <span class="hljs-keyword">return</span>
                <span class="hljs-keyword">const</span> timing = <span class="hljs-built_in">window</span>.performance.timing
                <span class="hljs-keyword">const</span> performance = {
                    <span class="hljs-comment">// &#x91CD;&#x5B9A;&#x5411;&#x8017;&#x65F6;</span>
                    redirect: timing.redirectEnd - timing.redirectStart,
                    <span class="hljs-comment">// &#x767D;&#x5C4F;&#x65F6;&#x95F4;</span>
                    whiteScreen: whiteScreen,
                    <span class="hljs-comment">// DOM &#x6E32;&#x67D3;&#x8017;&#x65F6;</span>
                    dom: timing.domComplete - timing.domLoading,
                    <span class="hljs-comment">// &#x9875;&#x9762;&#x52A0;&#x8F7D;&#x8017;&#x65F6;</span>
                    load: timing.loadEventEnd - timing.navigationStart,
                    <span class="hljs-comment">// &#x9875;&#x9762;&#x5378;&#x8F7D;&#x8017;&#x65F6;</span>
                    unload: timing.unloadEventEnd - timing.unloadEventStart,
                    <span class="hljs-comment">// &#x8BF7;&#x6C42;&#x8017;&#x65F6;</span>
                    request: timing.responseEnd - timing.requestStart,
                    <span class="hljs-comment">// &#x83B7;&#x53D6;&#x6027;&#x80FD;&#x4FE1;&#x606F;&#x65F6;&#x5F53;&#x524D;&#x65F6;&#x95F4;</span>
                    time: <span class="hljs-keyword">new</span> <span class="hljs-built_in">Date</span>().getTime(),
                }

                <span class="hljs-keyword">return</span> performance
            }

            <span class="hljs-comment">// &#x83B7;&#x53D6;&#x8D44;&#x6E90;&#x4FE1;&#x606F;</span>
            <span class="hljs-keyword">const</span> getResources = () =&gt; {
                <span class="hljs-keyword">if</span> (!<span class="hljs-built_in">window</span>.performance) <span class="hljs-keyword">return</span>
                <span class="hljs-keyword">const</span> data = <span class="hljs-built_in">window</span>.performance.getEntriesByType(<span class="hljs-string">&apos;resource&apos;</span>)
                <span class="hljs-keyword">const</span> resource = {
                    xmlhttprequest: [],
                    css: [],
                    other: [],
                    script: [],
                    img: [],
                    link: [],
                    fetch: [],
                    <span class="hljs-comment">// &#x83B7;&#x53D6;&#x8D44;&#x6E90;&#x4FE1;&#x606F;&#x65F6;&#x5F53;&#x524D;&#x65F6;&#x95F4;</span>
                    time: <span class="hljs-keyword">new</span> <span class="hljs-built_in">Date</span>().getTime(),
                }

                data.forEach(item =&gt; {
                    <span class="hljs-keyword">const</span> arry = resource[item.initiatorType]
                    arry &amp;&amp; arry.push({
                        <span class="hljs-comment">// &#x8D44;&#x6E90;&#x7684;&#x540D;&#x79F0;</span>
                        name: item.name,
                        <span class="hljs-comment">// &#x8D44;&#x6E90;&#x52A0;&#x8F7D;&#x8017;&#x65F6;</span>
                        duration: item.duration.toFixed(<span class="hljs-number">2</span>),
                        <span class="hljs-comment">// &#x8D44;&#x6E90;&#x5927;&#x5C0F;</span>
                        size: item.transferSize,
                        <span class="hljs-comment">// &#x8D44;&#x6E90;&#x6240;&#x7528;&#x534F;&#x8BAE;</span>
                        protocol: item.nextHopProtocol,
                    })
                })

                <span class="hljs-keyword">return</span> resource
            }

            <span class="hljs-built_in">window</span>.onload = () =&gt; {
                <span class="hljs-comment">// &#x5728;&#x6D4F;&#x89C8;&#x5668;&#x7A7A;&#x95F2;&#x65F6;&#x95F4;&#x83B7;&#x53D6;&#x6027;&#x80FD;&#x53CA;&#x8D44;&#x6E90;&#x4FE1;&#x606F; https://developer.mozilla.org/zh-CN/docs/Web/API/Window/requestIdleCallback</span>
                <span class="hljs-keyword">if</span> (<span class="hljs-built_in">window</span>.requestIdleCallback) {
                    <span class="hljs-built_in">window</span>.requestIdleCallback(() =&gt; {
                        monitor.performance = getPerformance()
                        monitor.resources = getResources()
                        <span class="hljs-built_in">console</span>.log(<span class="hljs-string">&apos;&#x9875;&#x9762;&#x6027;&#x80FD;&#x4FE1;&#x606F;&apos;</span>)
                        <span class="hljs-built_in">console</span>.log(monitor.performance)
                        <span class="hljs-built_in">console</span>.log(<span class="hljs-string">&apos;&#x9875;&#x9762;&#x8D44;&#x6E90;&#x4FE1;&#x606F;&apos;</span>)
                        <span class="hljs-built_in">console</span>.log(monitor.resources)
                    })
                } <span class="hljs-keyword">else</span> {
                    setTimeout(() =&gt; {
                        monitor.performance = getPerformance()
                        monitor.resources = getResources()
                        <span class="hljs-built_in">console</span>.log(<span class="hljs-string">&apos;&#x9875;&#x9762;&#x6027;&#x80FD;&#x4FE1;&#x606F;&apos;</span>)
                        <span class="hljs-built_in">console</span>.log(monitor.performance)
                        <span class="hljs-built_in">console</span>.log(<span class="hljs-string">&apos;&#x9875;&#x9762;&#x8D44;&#x6E90;&#x4FE1;&#x606F;&apos;</span>)
                        <span class="hljs-built_in">console</span>.log(monitor.resources)
                    }, <span class="hljs-number">0</span>)
                }
            }

            <span class="hljs-comment">// &#x6355;&#x83B7;&#x8D44;&#x6E90;&#x52A0;&#x8F7D;&#x5931;&#x8D25;&#x9519;&#x8BEF; js css img...</span>
            addEventListener(<span class="hljs-string">&apos;error&apos;</span>, e =&gt; {
                <span class="hljs-keyword">const</span> target = e.target
                <span class="hljs-keyword">if</span> (target != <span class="hljs-built_in">window</span>) {
                    monitor.errors.push({
                        type: target.localName,
                        url: target.src || target.href,
                        msg: (target.src || target.href) + <span class="hljs-string">&apos; is load error&apos;</span>,
                        <span class="hljs-comment">// &#x9519;&#x8BEF;&#x53D1;&#x751F;&#x7684;&#x65F6;&#x95F4;</span>
                        time: <span class="hljs-keyword">new</span> <span class="hljs-built_in">Date</span>().getTime(),
                    })

                    <span class="hljs-built_in">console</span>.log(<span class="hljs-string">&apos;&#x6240;&#x6709;&#x7684;&#x9519;&#x8BEF;&#x4FE1;&#x606F;&apos;</span>)
                    <span class="hljs-built_in">console</span>.log(monitor.errors)
                }
            }, <span class="hljs-literal">true</span>)

            <span class="hljs-comment">// &#x76D1;&#x542C; js &#x9519;&#x8BEF;</span>
            <span class="hljs-built_in">window</span>.onerror = <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">msg, url, row, col, error</span>) </span>{
                monitor.errors.push({
                    type: <span class="hljs-string">&apos;javascript&apos;</span>, <span class="hljs-comment">// &#x9519;&#x8BEF;&#x7C7B;&#x578B;</span>
                    row: row, <span class="hljs-comment">// &#x53D1;&#x751F;&#x9519;&#x8BEF;&#x65F6;&#x7684;&#x4EE3;&#x7801;&#x884C;&#x6570;</span>
                    col: col, <span class="hljs-comment">// &#x53D1;&#x751F;&#x9519;&#x8BEF;&#x65F6;&#x7684;&#x4EE3;&#x7801;&#x5217;&#x6570;</span>
                    msg: error &amp;&amp; error.stack? error.stack : msg, <span class="hljs-comment">// &#x9519;&#x8BEF;&#x4FE1;&#x606F;</span>
                    url: url, <span class="hljs-comment">// &#x9519;&#x8BEF;&#x6587;&#x4EF6;</span>
                    time: <span class="hljs-keyword">new</span> <span class="hljs-built_in">Date</span>().getTime(), <span class="hljs-comment">// &#x9519;&#x8BEF;&#x53D1;&#x751F;&#x7684;&#x65F6;&#x95F4;</span>
                })

                <span class="hljs-built_in">console</span>.log(<span class="hljs-string">&apos;&#x6240;&#x6709;&#x7684;&#x9519;&#x8BEF;&#x4FE1;&#x606F;&apos;</span>)
                <span class="hljs-built_in">console</span>.log(monitor.errors)
            }

            <span class="hljs-comment">// &#x76D1;&#x542C; promise &#x9519;&#x8BEF; &#x7F3A;&#x70B9;&#x662F;&#x83B7;&#x53D6;&#x4E0D;&#x5230;&#x884C;&#x6570;&#x6570;&#x636E;</span>
            addEventListener(<span class="hljs-string">&apos;unhandledrejection&apos;</span>, e =&gt; {
                monitor.errors.push({
                    type: <span class="hljs-string">&apos;promise&apos;</span>,
                    msg: (e.reason &amp;&amp; e.reason.msg) || e.reason || <span class="hljs-string">&apos;&apos;</span>,
                    <span class="hljs-comment">// &#x9519;&#x8BEF;&#x53D1;&#x751F;&#x7684;&#x65F6;&#x95F4;</span>
                    time: <span class="hljs-keyword">new</span> <span class="hljs-built_in">Date</span>().getTime(),
                })

                <span class="hljs-built_in">console</span>.log(<span class="hljs-string">&apos;&#x6240;&#x6709;&#x7684;&#x9519;&#x8BEF;&#x4FE1;&#x606F;&apos;</span>)
                <span class="hljs-built_in">console</span>.log(monitor.errors)
            })

            <span class="hljs-keyword">return</span> monitor
        }

        <span class="hljs-keyword">const</span> monitor = monitorInit()
    </span><span class="hljs-tag">&lt;/<span class="hljs-name">script</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">link</span> <span class="hljs-attr">rel</span>=<span class="hljs-string">&quot;stylesheet&quot;</span> <span class="hljs-attr">href</span>=<span class="hljs-string">&quot;test.css&quot;</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">title</span>&gt;</span>Document<span class="hljs-tag">&lt;/<span class="hljs-name">title</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">head</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">body</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">button</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;btn1&quot;</span>&gt;</span>&#x9519;&#x8BEF;&#x6D4B;&#x8BD5;&#x6309;&#x94AE;1<span class="hljs-tag">&lt;/<span class="hljs-name">button</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">button</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;btn2&quot;</span>&gt;</span>&#x9519;&#x8BEF;&#x6D4B;&#x8BD5;&#x6309;&#x94AE;2<span class="hljs-tag">&lt;/<span class="hljs-name">button</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">button</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;btn3&quot;</span>&gt;</span>&#x9519;&#x8BEF;&#x6D4B;&#x8BD5;&#x6309;&#x94AE;3<span class="hljs-tag">&lt;/<span class="hljs-name">button</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">img</span> <span class="hljs-attr">src</span>=<span class="hljs-string">&quot;https://avatars3.githubusercontent.com/u/22117876?s=460&amp;v=4&quot;</span> <span class="hljs-attr">alt</span>=<span class="hljs-string">&quot;&quot;</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">img</span> <span class="hljs-attr">src</span>=<span class="hljs-string">&quot;test.png&quot;</span> <span class="hljs-attr">alt</span>=<span class="hljs-string">&quot;&quot;</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">script</span> <span class="hljs-attr">src</span>=<span class="hljs-string">&quot;192.168.10.15/test.js&quot;</span>&gt;</span><span class="undefined"></span><span class="hljs-tag">&lt;/<span class="hljs-name">script</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">script</span>&gt;</span><span class="javascript">
<span class="hljs-built_in">document</span>.querySelector(<span class="hljs-string">&apos;.btn1&apos;</span>).onclick = () =&gt; {
    setTimeout(() =&gt; {
        <span class="hljs-built_in">console</span>.log(button)
    }, <span class="hljs-number">0</span>)
}

<span class="hljs-built_in">document</span>.querySelector(<span class="hljs-string">&apos;.btn2&apos;</span>).onclick = () =&gt; {
    <span class="hljs-keyword">new</span> <span class="hljs-built_in">Promise</span>((resolve, reject) =&gt; {
        reject({
            msg: <span class="hljs-string">&apos;test.js promise is error&apos;</span>
        })
    })
}

<span class="hljs-built_in">document</span>.querySelector(<span class="hljs-string">&apos;.btn3&apos;</span>).onclick = () =&gt; {
    <span class="hljs-keyword">throw</span> (<span class="hljs-string">&apos;&#x8FD9;&#x662F;&#x4E00;&#x4E2A;&#x624B;&#x52A8;&#x6254;&#x51FA;&#x7684;&#x9519;&#x8BEF;&apos;</span>)
}
</span><span class="hljs-tag">&lt;/<span class="hljs-name">script</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">body</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">html</span>&gt;</span>
</code></pre>
<h2 id="&#x53C2;&#x8003;&#x8D44;&#x6599;">&#x53C2;&#x8003;&#x8D44;&#x6599;</h2>
<p><a href="https://fex.baidu.com/blog/2014/05/build-performance-monitor-in-7-days/" target="_blank">https://fex.baidu.com/blog/2014/05/build-performance-monitor-in-7-days/</a></p>
<p><a href="https://github.com/wangweianger/zanePerfor" target="_blank">https://github.com/wangweianger/zanePerfor</a></p>

                                
                                </section>
                            
    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>

                        </div>
                    </div>
                
            </div>

            
                
                <a href="modal.html" class="navigation navigation-prev " aria-label="Previous page: Modal">
                    <i class="fa fa-angle-left"></i>
                </a>
                
                
                <a href="performance.html" class="navigation navigation-next " aria-label="Next page: Performance">
                    <i class="fa fa-angle-right"></i>
                </a>
                
            
        
    </div>

    <script>
        var gitbook = gitbook || [];
        gitbook.push(function() {
            gitbook.page.hasChanged({"page":{"title":"Monitor","level":"1.34","depth":1,"next":{"title":"Performance","level":"1.35","depth":1,"path":"前端进阶/performance.md","ref":"前端进阶/performance.md","articles":[]},"previous":{"title":"Modal","level":"1.33","depth":1,"path":"前端进阶/modal.md","ref":"前端进阶/modal.md","articles":[]},"dir":"ltr"},"config":{"gitbook":"*","theme":"default","variables":{},"plugins":["summary","livereload"],"pluginsConfig":{"summary":{},"livereload":{},"highlight":{},"search":{},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"fontsettings":{"theme":"white","family":"sans","size":2},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"}},"file":{"path":"前端进阶/monitor.md","mtime":"2021-02-15T12:04:36.000Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2021-03-24T08:50:55.666Z"},"basePath":"..","book":{"language":""}});
        });
    </script>
</div>

        
    <script src="../gitbook/gitbook.js"></script>
    <script src="../gitbook/theme.js"></script>
    
        
        <script src="../gitbook/gitbook-plugin-livereload/plugin.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-search/search-engine.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-search/search.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-lunr/lunr.min.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-lunr/search-lunr.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-sharing/buttons.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
        
    

    </body>
</html>

